package com.jinglin.web.controller;


import com.jinglin.annotation.RecordUserMessage;
import com.jinglin.controller.ABaseController;
import com.jinglin.entity.constants.Constants;
import com.jinglin.entity.enums.MessageTypeEnum;
import com.jinglin.entity.po.UserAction;
import com.jinglin.entity.vo.ResponseVO;
import com.jinglin.service.UserActionService;
import com.jinglin.web.annotation.GlobalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * <p>
 * 用户行为 点赞、评论 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2025-03-24
 */
@RestController
@RequestMapping("/userAction")
public class UserActionController extends ABaseController {
    @Autowired
    private UserActionService userActionService;

    @PostMapping("/doAction")
    @RecordUserMessage
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO doAction(@NotEmpty String videoId,
                               @NotNull Integer actionType,
                               @Max(2) @Min(1) Integer actionCount,
                               String commentId) {
        UserAction userAction = new UserAction();
        userAction.setUserId(getTokenUserInfoDto().getUserId());
        userAction.setVideoId(videoId);
        userAction.setActionType(actionType);
        actionCount = actionCount == null ? Constants.ONE : actionCount;
        userAction.setActionCount(actionCount);
        userAction.setCommentId(commentId);
        userAction.setActionTime(LocalDateTime.now());
        userActionService.saveAction(userAction);
        return getSuccessResponseVO(null);
    }
}

